@import 'function';
@import 'utils';

/* BEM
 -------------------------- */
@mixin b($block) {
    $B: $block !global;
    .#{$B} {
        @content;
    }
}

@mixin e($element) {
    $E: $element !global;
    $selector: &;
    $currentSelector: '';

    @each $unit in $element {
        $currentSelector: #{$currentSelector + '.' + $B + $element-separator + $unit + ','};
    }

    @if hitAllSpecialNestRule($selector) {
        @at-root {
            #{$selector} {
                #{$currentSelector} {
                    @content;
                }
            }
        }
    } @else {
        @at-root {
            #{$currentSelector} {
                @content;
            }
        }
    }
}

@mixin m($modifier) {
    $selector: &;
    $currentSelector: '';

    @each $unit in $modifier {
        $currentSelector: #{$currentSelector + & + $modifier-separator + $unit + ','};
    }

    @at-root {
        #{$currentSelector} {
            @content;
        }
    }
}

@mixin when($state) {
    @at-root {
        &.#{$state-prefix + $state} {
            @content;
        }
    }
}

@mixin pseudo($pseudo) {
    @at-root #{&}#{':#{$pseudo}'} {
        @content;
    }
}

@mixin spec-selector($specSelector: '', $element: $E, $modifier: false, $block: $B) {
    $modifierCombo: '';

    // 判断输出的是 b__e 还是 b__e--m
    @if $modifier {
        $modifierCombo: $modifier-separator + $modifier;
    }

    @at-root {
        #{&}#{$specSelector}.#{$block + $element-separator + $element + $modifierCombo} {
            @content;
        }
    }
}

@mixin share-rule($name) {
    $rule-name: '%shared-' + $name;

    @at-root #{$rule-name} {
        @content;
    }
}

@mixin extend-rule($name) {
    @extend #{'%shared-' + $name};
}
